import { observable, action, autorun, toJS } from 'mobx';
import { WeaLocaleProvider } from 'ecCom';


const getLabel = WeaLocaleProvider.getLabel;


/** ******  粘贴板相关  ******* */

class PasteBoard {
   constructor(parent) {
      this.parent = parent;
   }

   @observable pasteData = {}; // 数据结构： { id: data }
   @observable pasteType = ''; // 使用类型 copy or move

   // 修改粘贴板
   @action copyFiles = (copyData = {}) => {
      this.pasteData = copyData;
   };

   // 清空粘贴板
   @action clearPasteBoard = () => {
 this.pasteData = {}; 
};

   // 检查粘贴板数据是否合法 (通常在粘贴操作时)
   @action checkPasteValid = () => {
      const pasteData = toJS(this.pasteData);
      const dataSource = this.parent.viewSettings.type === 'icon' ? toJS(this.parent.fileSystem.data) : toJS(this.parent.fileSystem.tableStore.datas);
      for (let i in pasteData) {
         if (pasteData.hasOwnProperty(i)) {
            let target = dataSource.find(f => f.id === i);
            if (target === undefined) return false;
         }
      }
      return true;
   };

   // 监控粘贴板变化 改变右键菜单"粘贴"
   monitorPasteboardChanges = autorun(() => {
      const keys = Object.keys(this.pasteData);
      this.parent.rightMenu.changePasteItem(keys);
   });
}

export default PasteBoard;
